//#pragma GCC optimize(3)
//#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
//#define ll long long
#define int long long
//#define ull unsigned long long
//#define lll __int128
#define fi first
#define se second
//#define double long double
using namespace std;
const long long INF=1e9+5;
const long long mod=998244353,orm=3;
//const long long mod=1000000007;
const int MAXN=1000005;
const double eps=1e-6;
bool ST;
set<int> st;
int n,T,N;
int sum[MAXN];
struct o {
	int l,r;
}e[MAXN];
void sol() {
	N=st.size();
	vector<int> t; 
	for(int i:st) t.push_back(i);
	sort(t.begin(),t.end());
	for(int i=1;i<=N;i++) sum[i]=sum[i-1]+t[i-1];
	for(int i=1;i<N;i++) {
		int l=sum[i],r=sum[N]-sum[N-i]-1;
		e[i]={l,r};
	}
	sort(e+1,e+N,[](o x,o y){return x.l<y.l;});
	int l=-1,r=-2,res=0;
	for(int i=1;i<N;i++)  {
		if(r<e[i].l) {
			res+=r-l+1;l=e[i].l,r=e[i].r;
		}
		else {
			r=max(r,e[i].r);
		}
	}
	res+=r-l+1;
	cout<<res<<"\n";
}
void solve() {
	cin>>T;int tt=T;
	int sum=0;
	while(T--) {
		int x;cin>>x;
		if(st.count(x)) st.erase(x),sum-=x;
		else st.insert(x),sum+=x;
		if(st.size()<=1) cout<<"0\n";
		else if(st.size()<=100||tt<=1000) {
			sol();
		}
		else {
			int l=*st.begin(),r=sum-l-1;
			cout<<r-l+1<<"\n";
		}
	}
}
bool ED;
signed main() {
//	cout<<(&ST-&ED)/1024.0/1024.0;
	freopen("kte.in","r",stdin);
	freopen("kte.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	solve();
	return 0;
}
